/**
 * 模态框
 */
module.exports = function ($scope, $state, $resource, $stateParams, $modalInstance, $http, items) {

	$scope.obj = items;
	console.log(items);

	var promise = $http({
		url: '/api/as/tc/device/watchdevicetickettypelist',
		method: 'GET',
		params: { device_code: $scope.obj.code, view: $scope.obj.view }
	});
	promise.then(function (resp) {
		//resp是一个响应对象
		// console.log(resp);
		if (resp.data.errcode === 0) {
			$scope.objs = resp.data.data;
		} else {
			alert(resp.data.errmsg);
		}
	}, function (resp) {
		//带有错误信息的resp
		alert('处理响应失败');
	});

	$scope.selection = function ($event, obj) {
		var para = {
			'device_code': $scope.obj.code,
			'ticket_type': obj.code,
			'ticket_type_attr': obj.type_attr
		};
		var checkbox = $event.target;
		if (checkbox.checked) {
			var add = $http({
				url: '/api/as/tc/deviceauth/create',
				method: 'GET',
				params: para
			});
			add.then(function (resp) {
				//resp是一个响应对象
				console.log(resp.data);
			}, function (resp) {
				//带有错误信息的resp
				alert('处理响应失败');
			});
		} else {
			var del = $http({
				url: '/api/as/tc/deviceauth/delete',
				method: 'GET',
				params: para
			});
			del.then(function (resp) {
				//resp是一个响应对象
				console.log(resp.data);
			}, function (resp) {
				//带有错误信息的resp
				alert('处理响应失败');
			});
		}
	};

};